from tortoise import fields
from tortoise.models import Model

class LogsDB(Model):
    id = fields.IntField(pk=True, auto_generated=True)
    content = fields.TextField()
    type = fields.IntField(default=1, description='1->info;2->debug;3->error', null=True)
    status = fields.IntField(default=0)
    created_at = fields.DatetimeField(auto_now_add=True)

    def to_dict(self):
        return {
            'id': self.id,
            'content': self.content,
            'status': self.status,
            'type': self.type,
            'created_at': self.created_at.strftime("%Y/%m/%d %H:%M:%S")
        }

    class Meta:
        table = "logs"